#ifndef GAME_H
#define GAME_H

#include <QWidget>
#include <QMediaPlayer>
#include <QAudioOutput>
#include <QTimer>
#include <QTime>

#include "mylabel.h"
#include "bgwidget.h"

namespace Ui {
class game;
}

class game : public QWidget
{
    Q_OBJECT

public:
    QMediaPlayer* player;
    QAudioOutput* audioOutput;
    explicit game(QWidget *parent = 0);
    ~game();

    enum GestureDirect{
        LEFT,
        RIGHT,
        UP,
        DOWN
    };


    void createLabel();

    void initGame();

    bool merge(MyLabel *temp,int row,int col);

    bool isMerge();

    bool gameOver();

    void BGM(int x);

    void scorecheck();

    void saveGame();

    void releaseRes();

    void closeEvent(QCloseEvent *event);

    void keyPressEvent(QKeyEvent *event);

private:
    bool moveUp();
    bool moveDown();
    bool moveLeft();
    bool moveRight();

    bool isMergeUp(int row,int col);
    bool isMergeDown(int row,int col);
    bool isMergeLeft(int row,int col);
    bool isMergeRight(int row,int col);

signals:

    void GestureMove(GestureDirect direction);

    void ScoreChange();

private slots:

    void setScore();

    void moveLabel(GestureDirect direction);

    void on_bt_restart_clicked();

    void on_start_clicked();

    void on_remake_clicked();

    void on_stop_clicked();

    void update();


private:
    Ui::game *ui;
    int m_score;
    int m_highScore;
    int m_labelCount;
    MyLabel *labels[6][6];
    BGWidget * m_bgWidget;
    QTimer *ptimer;
    QTime baseTime;
    QString showStr;
};

#endif // GAMEWIDGET_H
